Channel: Automation Step by Step
Category: Education
Tags: selenium by raghav palhow to handle dropdown in selenium webdriverselenium free training for beginnersselenium how to select dropdownselenium how to select element
Description: All FREE courses - automationstepbystep.com 00:00 Introduction 00:36 How to select an option from drop-down 08:18 How to store dropdown options in a list 14:48 How to deselect an option from drop-down How to select an option from Dropdown Step 1 - Import select class from selenium import org.openqa.selenium.support.ui.Select; Step 2 - Create a select object by referring to the select element WebElement selectElement = driver.findElement(By.id("option")); Select selectObject = new Select(selectElement); Step 3 - select object will give you multiple commands to select selectObject.selectByIndex(1); selectObject.selectByValue("option 2"); selectObject.selectByVisibleText("Option 3"); How to store dropdown options in a list Step 1 - Import select class from selenium import org.openqa.selenium.support.ui.Select; Step 2 - Create a list of type WebElement for the dropdown List<WebElement> allAvailableOptions = selectObject.getOptions(); OR List<WebElement> options = driver.findElements(By.id("option")); Step 3 - Create a LOOP to access all options for(WebElement option : options) { System.out.println(option.getText()); } How to deselect an option from Dropdown selectObject.deselectByIndex(1); selectObject.deselectByValue("option 2"); selectObject.deselectByVisibleText("Option 3"); #seleniumbeginnertutorials Stories by Raghav - automationstepbystep.com/stories My Udemy Courses - automationstepbystep.com/udemy-discounts Every LIKE & SUBSCRIPTION gives me great motivation to keep working for you You can support my mission for education by sharing this knowledge and helping as many people as you can If my work has helped you, consider helping any animal near you, in any way you can Never Stop Learning Raghav